#!/usr/bin/env python

import os,sys
import shutil

if len(sys.argv) < 2:
	print('Usage: python_rm_build.py dir')
	#python python_rm_build.py D:\Ganji\CODE\V8.6.0-GanjiLife
	#python python_rm_build.py D:\Ganji\CODE\V8.6.0-GanjiLife\thirdparty
	#python python_rm_build.py D:\Ganji\CODE\V8.6.0-GanjiLife\samples
	sys.exit()

path=' '.join(sys.argv[1:])

def deleteBuildDir(dir):
	try:
		if os.path.isdir(dir):
			os.chdir(dir)
			cwd=os.getcwd()
			print('*** current dir,%s' % (cwd))
			
			for fn in os.listdir(cwd):
				if fn=="build":
					print('build dir')
					shutil.rmtree(fn)
				#else:
				#	print('other dir,%s' %(fn))

	except Exception:
		print("error")

deleteBuildDir(path)

if os.path.isdir(path):
	os.chdir(path)
	cwd=os.getcwd()
	print('*** second dir,%s' % (cwd))
	for fn in os.listdir(cwd):
		if os.path.isdir(fn):
			os.chdir(fn)
			deleteBuildDir(os.getcwd())
			os.chdir(path)
			cwd=os.getcwd()
print '*** Done'







